package edu.unf.cen6940.dao;

import edu.unf.cen6940.domain.Userlogin;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Userlogin entities.
 * 
 */
@Repository("UserloginDAO")
@Transactional
public class UserloginDAOImpl extends AbstractJpaDao<Userlogin> implements
		UserloginDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Userlogin.class }));

	/**
	 * EntityManager injected by Spring for persistence unit rms
	 *
	 */
	@PersistenceContext(unitName = "rms")
	private EntityManager entityManager;

	/**
	 * Instantiates a new UserloginDAOImpl
	 *
	 */
	public UserloginDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findUserloginByPasswordHashContaining
	 *
	 */
	@Transactional
	public Set<Userlogin> findUserloginByPasswordHashContaining(String passwordHash) throws DataAccessException {

		return findUserloginByPasswordHashContaining(passwordHash, -1, -1);
	}

	/**
	 * JPQL Query - findUserloginByPasswordHashContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Userlogin> findUserloginByPasswordHashContaining(String passwordHash, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findUserloginByPasswordHashContaining", startResult, maxRows, passwordHash);
		return new LinkedHashSet<Userlogin>(query.getResultList());
	}

	/**
	 * JPQL Query - findUserloginByUserLoginId
	 *
	 */
	@Transactional
	public Userlogin findUserloginByUserLoginId(Integer userLoginId) throws DataAccessException {

		return findUserloginByUserLoginId(userLoginId, -1, -1);
	}

	/**
	 * JPQL Query - findUserloginByUserLoginId
	 *
	 */

	@Transactional
	public Userlogin findUserloginByUserLoginId(Integer userLoginId, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findUserloginByUserLoginId", startResult, maxRows, userLoginId);
			return (edu.unf.cen6940.domain.Userlogin) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findAllUserlogins
	 *
	 */
	@Transactional
	public Set<Userlogin> findAllUserlogins() throws DataAccessException {

		return findAllUserlogins(-1, -1);
	}

	/**
	 * JPQL Query - findAllUserlogins
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Userlogin> findAllUserlogins(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllUserlogins", startResult, maxRows);
		return new LinkedHashSet<Userlogin>(query.getResultList());
	}

	/**
	 * JPQL Query - findUserloginByUserNameContaining
	 *
	 */
	@Transactional
	public Set<Userlogin> findUserloginByUserNameContaining(String userName) throws DataAccessException {

		return findUserloginByUserNameContaining(userName, -1, -1);
	}

	/**
	 * JPQL Query - findUserloginByUserNameContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Userlogin> findUserloginByUserNameContaining(String userName, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findUserloginByUserNameContaining", startResult, maxRows, userName);
		return new LinkedHashSet<Userlogin>(query.getResultList());
	}

	/**
	 * JPQL Query - findUserloginByPrimaryKey
	 *
	 */
	@Transactional
	public Userlogin findUserloginByPrimaryKey(Integer userLoginId) throws DataAccessException {

		return findUserloginByPrimaryKey(userLoginId, -1, -1);
	}

	/**
	 * JPQL Query - findUserloginByPrimaryKey
	 *
	 */

	@Transactional
	public Userlogin findUserloginByPrimaryKey(Integer userLoginId, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findUserloginByPrimaryKey", startResult, maxRows, userLoginId);
			return (edu.unf.cen6940.domain.Userlogin) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findUserloginByPasswordHash
	 *
	 */
	@Transactional
	public Set<Userlogin> findUserloginByPasswordHash(String passwordHash) throws DataAccessException {

		return findUserloginByPasswordHash(passwordHash, -1, -1);
	}

	/**
	 * JPQL Query - findUserloginByPasswordHash
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Userlogin> findUserloginByPasswordHash(String passwordHash, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findUserloginByPasswordHash", startResult, maxRows, passwordHash);
		return new LinkedHashSet<Userlogin>(query.getResultList());
	}

	/**
	 * JPQL Query - findUserloginByUserName
	 *
	 */
	@Transactional
	public Set<Userlogin> findUserloginByUserName(String userName) throws DataAccessException {

		return findUserloginByUserName(userName, -1, -1);
	}

	/**
	 * JPQL Query - findUserloginByUserName
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Userlogin> findUserloginByUserName(String userName, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findUserloginByUserName", startResult, maxRows, userName);
		return new LinkedHashSet<Userlogin>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Userlogin entity) {
		return true;
	}
}
